package com.lqfan.autoAnswerQ.dao.fileType;

import com.lqfan.autoAnswerQ.model.fileType.FileType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lqfan.autoAnswerQ.model.fileType.HandleFileType;
import com.lqfan.autoAnswerQ.model.quesBank.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lqfan
 * @since 2020-04-04
 */
@Mapper
public interface FileTypeMapper extends BaseMapper<FileType> {
    @Select("select id from fileType where filePath = #{filePath}")
    String selectFilePid(String filePath);

//    @Select("select q.*,f.* from fileType f ,question q where q.filePath=f.filePath and f.filePath =#{filePath} " +
//            "and f.userId=q.userId and f.userId =#{userId} and f.type = #{type}")

    @Delete("delete from fileType where filePath = #{path} and type=3 and userId =#{userId}")
    boolean deleteFileType(String path, String userId);

    @Delete("delete f.*,q.* from fileType f,question q where " +
            " f.userId = q.userId and f.userId =#{userId} and q.filePath =f.filePath and f.filePath like concat('%', #{path,jdbcType=VARCHAR}, '%') ")
    boolean deleteFiles(String path, String userId);

    @Select("select f.*,q.id qid,q.questionName,q.questionTime,q.questionFileType,q.doNumber from fileType f,question q where f.userId=q.userId and f.userId=#{userId} and q.filePath = f.filePath and q.questionFileType<>5 and f.type=#{type} and q.questionName like concat('%', #{questionName,jdbcType=VARCHAR}, '%')")
    List<HandleFileType> getPath(String userId,int type,String questionName);

    @Select("select f.*,q.id qid,q.questionName,q.questionTime,q.questionFileType,q.doNumber from fileType f,question q where f.userId=q.userId and f.userId=#{userId} and q.filePath = f.filePath and q.questionFileType=5 and f.type=#{type} and q.questionName like concat('%', #{questionName,jdbcType=VARCHAR}, '%')")
    List<HandleFileType> getFilePath(String userId, int type, String questionName);
}
